package gui;

import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Node;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL14;
import org.lwjgl.opengl.GL20;

/**
 * test
 * @author normenhansen
 */
public class AppTreeGenerator extends SimpleApplication {  
    
    @Override
    public void simpleInitApp() {
        adjustKeyboardLayout("AZERTY");
        getInputManager().setCursorVisible(true);   
        inputManager.addMapping("changeCam", new KeyTrigger(KeyInput.KEY_C));
        inputManager.addListener(new ActionListener() {
            public void onAction(String name, boolean isPressed, float tpf) {
                if(!isPressed){
                    Camera c = getCamera();
                    if(c.isParallelProjection()){
                        c.setParallelProjection(false);
                    }else{
                        
                    }
                }
            }
        }, new String[]{"changeCam"});
        
        GL11.glEnable(GL20.GL_POINT_SPRITE);
        GL11.glTexEnvi(GL20.GL_POINT_SPRITE, GL20.GL_COORD_REPLACE, GL11.GL_TRUE);
        GL11.glEnable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);
//        GL14.glPointParameterf( GL14.GL_POINT_FADE_THRESHOLD_SIZE, 60.0f );
        GL14.glPointParameterf( GL14.GL_POINT_SIZE_MIN, 1.0f );

        GL11.glEnable(GL13.GL_MULTISAMPLE);
        GL11.glEnable(GL13.GL_SAMPLE_ALPHA_TO_COVERAGE);
    }

    @Override
    public void simpleUpdate(float tpf) {
        
    }

    @Override
    public void simpleRender(RenderManager rm) {
        
    }
    
    private void adjustKeyboardLayout(String layout){               
        
        //Starting from default qwerty configuration
        inputManager.deleteTrigger("FLYCAM_Forward", new KeyTrigger(KeyInput.KEY_W));
        inputManager.deleteTrigger("FLYCAM_Backward", new KeyTrigger(KeyInput.KEY_S));
        inputManager.deleteTrigger("FLYCAM_StrafeLeft", new KeyTrigger(KeyInput.KEY_A));
        inputManager.deleteTrigger("FLYCAM_StrafeRight", new KeyTrigger(KeyInput.KEY_D));
        inputManager.deleteTrigger("FLYCAM_Rise", new KeyTrigger(KeyInput.KEY_Q));
        inputManager.deleteTrigger("FLYCAM_Lower", new KeyTrigger(KeyInput.KEY_Z));        
        
        if(layout.equals("AZERTY")){
         inputManager.addMapping("FLYCAM_Forward", new KeyTrigger(KeyInput.KEY_Z));
         inputManager.addMapping("FLYCAM_Backward", new KeyTrigger(KeyInput.KEY_S));
         inputManager.addMapping("FLYCAM_StrafeLeft", new KeyTrigger(KeyInput.KEY_Q));
         inputManager.addMapping("FLYCAM_StrafeRight", new KeyTrigger(KeyInput.KEY_D));
         inputManager.addMapping("FLYCAM_Rise", new KeyTrigger(KeyInput.KEY_A));
         inputManager.addMapping("FLYCAM_Lower", new KeyTrigger(KeyInput.KEY_W));            
        
        }
        else if(layout.equals("QWERTZ")){            
         inputManager.addMapping("FLYCAM_Forward", new KeyTrigger(KeyInput.KEY_Z));
         inputManager.addMapping("FLYCAM_Backward", new KeyTrigger(KeyInput.KEY_S));
         inputManager.addMapping("FLYCAM_StrafeLeft", new KeyTrigger(KeyInput.KEY_A));
         inputManager.addMapping("FLYCAM_StrafeRight", new KeyTrigger(KeyInput.KEY_D));
         inputManager.addMapping("FLYCAM_Rise", new KeyTrigger(KeyInput.KEY_Q));
         inputManager.addMapping("FLYCAM_Lower", new KeyTrigger(KeyInput.KEY_Y));
        }                
   }
    
    public Node getRootNode(){
        return rootNode;
    }
        
}
